home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 422_04 / MBASIC.DOC < prev    next >
Encoding:
Text File  |  1994-02-13  |  44.9 KB  |  995 lines

  1.    
  2.    
  3.    
  4.    
  5.    
  6.    
  7.    
  8.    
  9.    
  10.    
  11.    
  12.    
  13.    
  14.    
  15.    
  16.    
  17.    
  18.    
  19.    
  20.    
  21.                            Micro Basic Users Guide
  22.    
  23.       I originally wrote Micro Basic in  1980  for  a  University  Computer
  24.    Club, in which the members were building their own 8085 based systems.
  25.    
  26.                                 Dave Dunfield
  27.    MICRO BASIC USERS GUIDE                                          Page: 1
  28.  
  29.  
  30.    1. INTRODUCTION
  31.    
  32.          Micro Basic was implemented with the intention  of  providing  the
  33.       maximum amount of features and flexibility, in the minimum amount  of
  34.       memory space. It is intended for use on 8080/8085/Z80 based computers
  35.       which are too small to afford the use of larger programming  systems.
  36.       Currently, the Micro Basic  interpreter,  is  3K  bytes  in  size.  A
  37.       machine-language MONITOR and all hardware dependant I/O routines  are
  38.       also included, bringing the total rom size to 4K. A minimum of 3K  of
  39.       ram is required if any useful programs  are to  be  implemented.  The
  40.       interpreter only makes use of memory as it needs it, and  memory  can
  41.       be expanded at any time, to allow for larger programs or  more  array
  42.       space.  Micro  Basic  is  quite  different  from  most  other   BASIC
  43.       interpreters,  in  particular  the  right  to   left   execution   of
  44.       expressions, with no operator precedence, and  the  use  of  separate
  45.       operators for EQUALS and ASSIGNMENT. These implementation  decisions,
  46.       were in part, based on the language APL, which is a favorite language
  47.       of the author.
  48.    
  49.          The Micro Basic rom, is assembled to  go  at  location  zero,  and
  50.       occupies the range of addresses from 0000-0FFF. The software supports
  51.       a 16 line by 64 character 1K  memory  mapped  video  display,  to  be
  52.       located in the address range from 1000-13FF. The  system  RAM  should
  53.       start at 1400 and may continue on up to FFFF. The keyboard should  be
  54.       on a parallel input port,  located  as  port#0,  with  the  keystrobe
  55.       (active high) on bit#7, and ASCII data is expected on bits  0-6.  The
  56.       keystrobe should remain high for as long as the key  is  pressed. The
  57.       serial I/O for the tape is expected to be an INTEL 8251 with the data
  58.       port mapped as port#1, and the control port as  port#2.  The  receive
  59.       and transmit clocks should be 16x the desired speed.
  60.    
  61.          On the following pages, is a brief description  of  Micro  Basic's
  62.       commands and features.
  63.    MICRO BASIC USERS GUIDE                                          Page: 2
  64.  
  65.  
  66.    2. COMMANDS
  67.    
  68.          Operands to commands are as followes:
  69.    
  70.          <e> - Any expression.
  71.          <v> - Any variable.
  72.          <a> - Any array variable.
  73.          <n> - Any numeric expression.
  74.          <l> - A line number.
  75.          [ ] - Optional operands.
  76.          ... - Multiple extra operands allowed.
  77.    
  78.       2.1 General commands
  79.    
  80.             The following  commands,  may  be  entered  directly  from  the
  81.          keyboard, or executed with a BASIC program.
  82.    
  83.          CLEAR
  84.    
  85.             Clears  all  numeric  and  character  variables,  Delete's  all
  86.          arrays, and resets the control stack and data pointer.
  87.    
  88.          DIM a1(<n1>)[,a2(n2)]...
  89.    
  90.             Dimensions integer arrays a1, a2,... makeing  them  n1,  n2,...
  91.          elements each. Arrays may be REDIMENSIONED with the DIM statement,
  92.          however this allocates new memory for the array, causing  the  old
  93.          memory used by the old array to be  made  unusable  (until  'NEW',
  94.          'CLEAR' or a 'RUN'  command  is  issued).  Whenever  an  array  is
  95.          dimensioned or redimensioned via DIM, it is cleared to zeros.
  96.    
  97.          NOTE: Array space is allocated in memory, starting at the  end  of
  98.                the program source. As a result, if a line is inserted  into
  99.                the program, or any line is replaced  in  the  program,  any
  100.                existing arrays will be deleted.
  101.    
  102.          END
  103.    
  104.             Stops the program. no messages are issued.
  105.    
  106.          EXIT
  107.    
  108.             Exits to the system monitor.
  109.    
  110.          GOTO <line#>
  111.    
  112.             Transfers program execution to the statement at  the  beginning
  113.          of line <line#>.
  114.    
  115.          GOTO(<n>),<l1>[,<l2>]...
  116.    
  117.             Transfers program execution to the statement at  the  beginning
  118.          of line <l1> if <n>=0, to the beginning of  line  <l2>  if  <n>=1,
  119.          etc. results in SYNTAX ERROR if <n> is greater than number of line
  120.          numbers given.
  121.    MICRO BASIC USERS GUIDE                                          Page: 3
  122.  
  123.  
  124.          INPUT <v>
  125.    
  126.             Requests a value for <v> from  the  terminal.  Prompts  with  a
  127.          question mark "?". If <v> is a character variable, then  any  text
  128.          can be input. If <v> is numeric, then value  supplied  must  be  a
  129.          number or expression.
  130.    
  131.          INPUT "<text>",<v>
  132.    
  133.             Same as above, but prompts with <text> instead of  "?".  <text>
  134.          can be a null string ( INPUT "",<v> would give no prompt ).
  135.    
  136.          NOTE: The value of a character variable can be used in the prompt,
  137.                but must be concatinated with <text>. EG: ' INPUT ""+A$,V '.
  138.    
  139.          LET <v>=<e> (default)
  140.    
  141.             Assigns the value of <e> to the variable <v>. If any lines  are
  142.          found by the interpreter which do not contain a command, then they
  143.          are assumed to be LET.
  144.    
  145.          LIST [<l1>][,<l2>]
  146.    
  147.             Lists the program,if no operands  are  given,  then  lists  the
  148.          entire program. If <l1> is given then only that line is listed. If
  149.          <l2> is also given, then lists from <l1> to <l2> inclusive.
  150.    
  151.          LOAD
  152.    
  153.             Loads  a  program  from  tape.  Flashes  a  '*'  in  the  upper
  154.          right-hand corner of the screen for every record (255 Bytes)  that
  155.          is loaded.
  156.    
  157.          NEW
  158.    
  159.             Clears the program, variables, and arrays.
  160.    
  161.          ORDER <line#>
  162.    
  163.             Positions the read pointer to the start of  the  line  <line#>.
  164.          This line must begin with a DATA statement, or a  DATA ERROR  will
  165.          occur.
  166.    
  167.          PRINT <e>[,<e>][,<e>]...[,]
  168.    
  169.             Prints the expressions on the terminal. Numeric values will  be
  170.          printed with  a  preceding  space.  If  a  numeric  expression  is
  171.          preceded by a single '(', then the preceding space is not printed.
  172.          ( EG: PRINT 12,(12 would  display  '  1212'  ).  If  the  list  of
  173.          expressions ends with a trailing comma, then no line-feed carriage
  174.          return will be  printed,  causing  the  next  PRINT  statement  to
  175.          continue at the end of the same line.
  176.    MICRO BASIC USERS GUIDE                                          Page: 4
  177.  
  178.  
  179.          PLOT <x>,<y>[,<e>][,<e>]...[,]
  180.    
  181.             Same as PRINT, except cursor is positioned at column <x>,  line
  182.          <y> (from the top lefthand corner of the screen), before the  rest
  183.          of  the  operands  are  printed.  'PLOT  <x>,<y>'  with  no  other
  184.          operands, will position the cursor with no output.
  185.    
  186.          READ <v>[,<v>]...
  187.    
  188.             Reads the values for variables from data statements.  An  ORDER
  189.          statement must be done before the first read  in  a  program,  and
  190.          anytime that you have read all the data in a data  block.  A  data
  191.          block, is a  collection  of  data  statements  which  are  located
  192.          separately, with no other  statements  between  them.  If  a  read
  193.          statement does not read all of the data in a given data statement,
  194.          then the next read will pick up where the last one left off. If  a
  195.          read statement reads beyond the end of a data  statement,  the  it
  196.          will advance to the next statement and attempt to read from there.
  197.    
  198.          REM <text>
  199.    
  200.             Comment, the rest of the statement is ignored.
  201.    
  202.          RUN
  203.    
  204.             Clears variables and arrays, then starts the program running. A
  205.          running program can be stopped by pressing CONTROL-C.
  206.    
  207.          SAVE
  208.    
  209.             Saves a program on tape.
  210.    
  211.          SIZE
  212.    
  213.             Prints the size of the program in bytes.
  214.    
  215.          STOP
  216.    
  217.             Stops the program, issues message indicating line number  where
  218.          it was executing.
  219.    
  220.          USR <n1>[,<n2>][,<v>]
  221.    
  222.             Calls a user supplied machine code routine at address <n1>.  If
  223.          <n2> is given, its value will be passed in the H-L register  pair.
  224.          If <v> is given, it must  be  a  numeric  variable,  and  will  be
  225.          assigned the value of  H-L  after  the  machine  language  routine
  226.          returns.
  227.    MICRO BASIC USERS GUIDE                                          Page: 5
  228.  
  229.  
  230.       2.2 Program only commands
  231.    
  232.             The following commands, can only be executed within a program.
  233.    
  234.          DATA <e>[,<e>]...
  235.    
  236.             Defines program DATA, to be read by the  READ  statement,  into
  237.          program  variables.  DATA  statements  are  not  executed  by  the
  238.          interpreter.
  239.    
  240.          NOTE: Variables can be used in the DATA statements,  but the value
  241.                will be evaluated as the value of that variable at the  time
  242.                that the DATA statement is read.
  243.    
  244.          FOR <v>=<n1> TO <n2>
  245.    
  246.             Starts a program loop. The variable <v> will be set to <n1>.and
  247.          will be incremented by one every time around the  loop.  until  it
  248.          value is equal to <n2>. <v> must be a simple numeric variable. See
  249.          also 'NEXT' statement.
  250.    
  251.          GOSUB <line#>
  252.    
  253.             Calls a  BASIC  subroutine  at  given  line  number.  (Same  as
  254.          goto,but stacks return address.) See also 'RETURN' statement.
  255.    
  256.          GOSUB(<n>),<l1>,<l2>...
  257.    
  258.             Same  as  above,  but  uses  computed  line  number.  See  also
  259.          'GOTO(<n>)'.
  260.    
  261.          IF <e> THEN <stmt>
  262.    
  263.             Evaluates  <e>,  If  it  is  true  (non-zero)  then  <stmt>  is
  264.          executed. If <stmt> is a number, then assumes GOTO <stmt>.
  265.    
  266.          LIF <e> THEN <stmts>
  267.    
  268.             Long IF, same as IF, except that the entire  remainder  of  the
  269.          line is executed only if the expression <e> is true.
  270.    
  271.          NEXT <v>
  272.    
  273.             Closes a program loop. <v> must match the <v> in  the  matching
  274.          'FOR' statement.
  275.    
  276.          RETURN
  277.    
  278.             Returns to statement following GOSUB statement.  (Terminates  a
  279.          BASIC subroutine)
  280.    MICRO BASIC USERS GUIDE                                          Page: 6
  281.  
  282.  
  283.    3. EXPRESSIONS
  284.    
  285.          Expressions can be either numeric or character.  all  expressions,
  286.       are evaluated from right to left, with NO operator precedence (as  in
  287.       the language APL). For example, 1+5*5 evaluates to 26, but 5*5+1 will
  288.       give the answer 30. Precedence can be forced in  numeric  expressions
  289.       with the use of brackets "()". Brackets can be nested to any depth.
  290.    
  291.       3.1 Numeric operators
  292.    
  293.             FORMAT: "X<operator>Y"
  294.    
  295.            +   Addition. 
  296.    
  297.            -   Subtraction.
  298.    
  299.            *   Multiplication.
  300.    
  301.            %   Division. (Remainder assigned to special variable "R").
  302.    
  303.            &   Bitwise logical AND of X and Y.
  304.    
  305.            |   Bitwise logical OR of X and Y.
  306.    
  307.            \   Floor. (returns lesser of X and Y).
  308.    
  309.            /   Ceiling. (returns greater of X and Y).
  310.    
  311.            =   Assignment. (X takes value of Y).
  312.    
  313.            ==  Equality. (returns 1 if X equals Y, 0 otherwise).
  314.    
  315.            >   Greater than. (returns 1 if X greater than Y, 0 otherwise).
  316.    
  317.            <   Less than. (returns 1 if X less than Y, 0 otherwise).
  318.    
  319.            >=  Greater equals. (Returns 1 if X GE Y, 0 otherwise). 
  320.    
  321.            <=  Less equals. (Returns 1 if X LE Y, 0 otherwise).
  322.    
  323.            -=  Not equals. (Returns 1 if X not equal to Y, 0 otherwise).
  324.    
  325.            ;   Null operator, returns value of X. (but executes Y).
  326.                Especially useful for doing modular arithmetic.
  327.                The expression "A=R;B%123" will divide B by 123 (without
  328.                changing B), and then assign the remainder to A. (Right
  329.                to left execution).
  330.    MICRO BASIC USERS GUIDE                                          Page: 7
  331.  
  332.  
  333.    3.2 Character operators
  334.    
  335.        FORMAT: "X$<operator>Y$"
  336.    
  337.            +   Concatonation. (Y$ appended to X$).
  338.    
  339.            =   Assignment. (X$ takes value of Y$).
  340.    
  341.            ==  Equality. (only valid in "IF" and Numeric conversion).
  342.    
  343.            -=  Not equals. (only valid in "IF" and numeric converson)
  344.    
  345.    The following are other operators which perform useful functions:
  346.    
  347.            ( ) Brackets, Force operator precedence.
  348.    
  349.            [ ] Braces, Used to index numeric arrays, E.G. "A[10]"
  350.                Also can be used to extract a single character
  351.                from a character variable. E.G. "A[0]$" returns
  352.                the first character in variable "A$".
  353.                (Index starts at zero (0) ).
  354.    
  355.            #   Hexidecimal constants. EG. "A=FF#+1" calculates "FF#"
  356.                as 255, adds 1 then assigns result (256) to "A".
  357.    
  358.            :   Statement separator, can be used to place multiple
  359.                statements on a single program line: E.G: "A=10:PRINT A"
  360.    
  361.            ,   Operand separator, separates operands to some commands.
  362.    
  363.       3.3 Numeric conversion
  364.    
  365.             A character expression can be included in a numeric expression,
  366.          but must be contained in brackets "()". If the  leftmost  operator
  367.          in the character expression is one of "==" or "-=", then a 1 or  0
  368.          is returned to the numeric (outside) expression. If  the  leftmost
  369.          operator  of  the  character  expression  is  "=",then  the  value
  370.          returned is the ASCII value of the  first  character  of  the  OLD
  371.          value of the character variable. Otherwise the ASCII value of  the
  372.          first character in the  result  of  the  character  expression  is
  373.          returned. The ASCII value of a character, is the decimal value  of
  374.          it's binary representation. (E.G. " " (blank) is 32).  If  a  null
  375.          string ("") is the result of the expression,then the value 255  is
  376.          returned (ASCII values for characters can only  range  from  0  to
  377.          127). The expression within the brackets does not have to  contain
  378.          operators, I.E. " PRINT ("A") " will  print  a  65.  (The  decimal
  379.          value of an ASCII "A").
  380.    MICRO BASIC USERS GUIDE                                          Page: 8
  381.  
  382.  
  383.       3.4 Variables
  384.    
  385.             There are 26 simple integer variables  (A-Z).  These  variables
  386.          always exist and are cleared to zero when BASIC is entered, when a
  387.          NEW command is executed, and when a program is RUN.  Integers  are
  388.          positive, with a range of 0 to 65535 (16 bits of data).
  389.    
  390.             There are also up to 26 integer arrays, (A[n] - Z[n]). An array
  391.          must be created (via the 'DIM' command) before it  exists.  Arrays
  392.          are cleared to zero's when they are created.
  393.    
  394.             Arrays  when  dimensioned,  (DIM  A(n))  have   n+1   elements,
  395.          subscripts ranging form 0 to n. Subscripts are not checked by  the
  396.          interpreter, therefore, if you type 'DIM A(10),B(10)'  then  A[11]
  397.          is the same as B[0].
  398.    
  399.             There are 26  character  variables,  (A$-Z$).  These  variables
  400.          always exist and are cleared to null strings ("")  when  BASIC  is
  401.          entered, when a NEW is executed,and when a program  is  RUN.  Each
  402.          character variable can hold up to 35  characters.  The  individual
  403.          characters can be read using braces between the character variable
  404.          name, and the dollar sign. (ie. A[0]$ to A[34]$). If an  index  is
  405.          greater than 34, a DIMENSION ERROR will result.  If  an  index  is
  406.          greater than the number of characters currently in  the  variable,
  407.          but less than 35, then  a  null  string  ("")  will  be  returned.
  408.          Character variables cannot be assigned values in this manner.
  409.    
  410.             The variable names are all separate, you can have A,  A[n]  and
  411.          A$, all in the same program, without interaction between them.
  412.    MICRO BASIC USERS GUIDE                                          Page: 9
  413.  
  414.  
  415.       3.5 Special variables
  416.    
  417.             The simple integer variable 'R' is a special  variable  because
  418.          it will be assigned the remainder whenever a divide  operation  is
  419.          executed.
  420.    
  421.             The following are special variables, unlike 'R', they cannot be
  422.          used as 'normal' variables:
  423.    
  424.           @[n] This variable can only be referenced as an array. When read,
  425.                it returns the BYTE value (0-255) of the memory  location at
  426.                its index (n). When assigned a value,  that  value  will  be
  427.                assigned to the memory location at its index  (n).  (if  the
  428.                value assigned is > 255 Then it is divided by 256,  and  the
  429.                remainder is used). This is the Same function as 'PEEK'  and
  430.                'POKE' in some other BASIC's.
  431.    
  432.          @[n]$ This character variable, can  only  be  referenced  with  an
  433.                index. Its index can range from 0 to 255. It will return the
  434.                character which has the binary value of its index.  (if  255
  435.                is used, it will return a null  string.  This  is  the  same
  436.                function as 'CHR$' in some other basics.
  437.    
  438.              ? This variable can only be referenced  as  a  simple  integer
  439.                variable When read, it returns a random  number  from  0  to
  440.                65535. When given a value, it sets the random seed  to  that
  441.                value. Random numbers can be generated within limits by  the
  442.                use of modular arithmetic. (EG. to generate a random  number
  443.                between 0 and 99, and assign it to the variable 'A', use the
  444.                command 'A=R;?%100').This is similar to the  'RND'  function
  445.                of some other basics.
  446.    MICRO BASIC USERS GUIDE                                          Page: 10
  447.  
  448.  
  449.    4. PROGRAM ENTRY AND EDITING
  450.    
  451.          To enter or replace a line, simply enter it's line number starting
  452.       in column one, followed by the text for the new  line.  To  delete  a
  453.       line, just enter it's line number, with no following text.
  454.    
  455.          When a line is entered, (and return is pressed), it is copied into
  456.       a buffer. Parts or all of this old line can  be  included  in  a  new
  457.       line, as it is typed in. When the new line is entered,it then becomes
  458.       the old line. A pointer is kept, indicating the current  position  in
  459.       the old line. The following functions are available to  perform  this
  460.       'editing'.
  461.    
  462.       CTRL-A
  463.    
  464.          Advance: Copy one character from the old line into the  new  line,
  465.       and advance the pointer to the next character in the old line.
  466.    
  467.       CTRL-C
  468.    
  469.          Cancel: Cancels the (partially) complete  new  line,  and  restart
  470.       from the beginning. (resets old line pointer).
  471.    
  472.       CTRL-D
  473.    
  474.          Delete: Advances the old line pointer by  one  character,deleteing
  475.       that character from the old line. the new line is not affected. A '*'
  476.       character is printed to indicate this has been done.
  477.    
  478.       CTRL-F
  479.    
  480.          Find: This command requires one extra  character  to  be  entered.
  481.       When it is,  the  old  line  is  copied  (from  the  current  pointer
  482.       position) into the new line,  up  to  but  NOT  including  the  first
  483.       occurance of that character. The pointer is advanced to point to  the
  484.       character found. If the character is not found, no action is taken.If
  485.       the second character is a carriage return,the remainder  of  the  old
  486.       line will be copied into the new line.
  487.    
  488.       CTRL-H
  489.    
  490.          Backup: This backs up one character,deleteing the  last  character
  491.       entered, and backs up the old line pointer  in  the  old  line.  This
  492.       effectively cancels the effect of the last  character  entered.  (The
  493.       DELETE key also invokes this function).
  494.    
  495.       CTRL-M
  496.    
  497.          Carriage Return: enters the new line, causing  it  to  become  the
  498.       (new) old line, and passes it to the interpreter, as input.
  499.    MICRO BASIC USERS GUIDE                                          Page: 11
  500.  
  501.  
  502.       CTRL-I
  503.    
  504.          Insert: Toggles insert mode. a "<" is printed when entering insert
  505.       mode a ">" is printed when leaving insert mode.  Normally,  when  you
  506.       enter text into the new line, the old line pointer  is  advanced,  so
  507.       that the characters you are typing, effectivly replace the characters
  508.       in the old line. In insert mode, this does not happen, therefore  the
  509.       characters you are typing, can be inserted into the old line. (If  it
  510.       is later copied into the new line).
  511.    
  512.          The line editor can be used to EDIT program  lines,  When  a  list
  513.       command is executed, the last line listed will be made the old  line.
  514.       To modify line 50, you would just have to type 'LIST 50'. This  would
  515.       display line 50, and would also store it  in  the  old  line  buffer.
  516.       Whenever a  program  stops  due  to  an  error,  CTRL-C,  or  a  STOP
  517.       statement, the line it stopped on will also be stored in the old line
  518.       buffer, ready for editing.
  519.    MICRO BASIC USERS GUIDE                                          Page: 12
  520.  
  521.  
  522.    5. CONTROL CHARACTERS
  523.    
  524.          The following control characters (other than the  ones  recognised
  525.       by the line editor) are recognised. All other control characters, are
  526.       ignored by the interpreter.
  527.    
  528.       CTRL-C
  529.    
  530.          Will abort any program, terminated with the message "STOP IN  LINE
  531.       XXXX" where XXXX is the number of the line containing  the  statement
  532.       which would have been executed next.  Will  also  abort  program,  if
  533.       entered when responding to an INPUT statement, but will not print the
  534.       "STOP" message. Will also abort output from the LIST command.
  535.    
  536.       CTRL-J (line feed)
  537.    
  538.          Will stop terminal output and/or program execution, for as long as
  539.       the key is held down. When  released,  output/execution  will  resume
  540.       normally.
  541.    
  542.       CTRL-N (SI)
  543.    
  544.          This character, will be ignored when entered  from  the  keyboard,
  545.       but when printed, will  cause  the  eighth  bit  to  be  set  in  all
  546.       subsequent characters which  are  printed.  Depending  on  the  video
  547.       display used,  this  will  cause  REVERSE  VIDEO,  FLASHING,  DIM  or
  548.       BRIGHTER output, GRAPHICS CHARACTERS, or  will  have  NO  EFFECT  (If
  549.       display ignores extra bit).
  550.    
  551.       CTRL-O (SO)
  552.    
  553.          This character, will be ignored when entered  from  the  keyboard,
  554.       but when printed, will cause the eighth bit  to  be  cleared  in  all
  555.       characters which are subsequently printed. This will  restore  normal
  556.       operation if a special  effect  was  invoked  via  the  CNTRL-N  (SI)
  557.       control character above. For example, if  your  video  display  gives
  558.       reverse video when the eighth bit  is  set,then  you  could  use  the
  559.       following statement to print "REVERSE" in reverse video:
  560.    
  561.                       ' PRINT @[14]$,"REVERSE",@[15]$ '
  562.    
  563.       CTRL-L (FF)
  564.    
  565.          No effect from keyboard, Clears the screen and  homes  the  cursor
  566.       when printed. Eg: ' PRINT @[12]$ '
  567.    
  568.       CTRL-K (VT)
  569.    
  570.          No effect from keyboard, Homes the  cursor  when  printed.  Eg:  '
  571.       PRINT @[11]$ '
  572.    MICRO BASIC USERS GUIDE                                          Page: 13
  573.  
  574.  
  575.    6. ERROR MESSAGES
  576.    
  577.          Below is a list of error messages  produced  by  the  interpreter.
  578.       Errors occuring in a program, will be followed by  "  IN  LINE  XXXX"
  579.       where XXXX is the line on which the error was discovered. All  errors
  580.       except '?BAD DATA - RETRY' are fatal,  and  will  stop  an  executing
  581.       program.
  582.    
  583.       ?SYNTAX ERROR
  584.    
  585.          Results from a statement that is not decodeable. (Does not  follow
  586.       syntax) Also results if you attempt to use a  command  in  the  wrong
  587.       context. Ie. You use a  command  from  the  keyboard  which  is  only
  588.       allowed from within a program.
  589.    
  590.       ?NO PROGRAM ERROR
  591.    
  592.          Results from an attempt to RUN or to SAVE an zero line program.
  593.    
  594.       ?DIMENSION ERROR
  595.    
  596.          Results from an  attempt  to  index  a  non-array  variable,  from
  597.       indexing a character variable  with  a  value  greater  than  34,  or
  598.       attempt to PLOT outside the screen.
  599.    
  600.       ?DIVIDE BY ZERO ERROR
  601.    
  602.          Results from attempt to divide any value by zero.
  603.    
  604.       ?LINE NUMBER ERROR
  605.    
  606.          Results from reference to a program  line  number  that  does  not
  607.       exist.
  608.    
  609.       ?DATA ERROR
  610.    
  611.          Results from attempt to ORDER to a line which does not start  with
  612.       a DATA statement, attempt to READ before you have executed an  ORDER,
  613.       reading beyond the end of a DATA BLOCK, or  from  reading  the  wrong
  614.       data type (character or numeric) for the operand variable.
  615.    
  616.       ?NESTING ERROR
  617.    
  618.          Results from improper nesting of GOSUB/RETURN or FOR/NEXT loops.
  619.    
  620.       ?BAD DATA - RETRY
  621.    
  622.          Results from any error  in  a  numeric  expression  typed  as  the
  623.       response to an INPUT to  a  numeric  variable.  Does  not  stop,  but
  624.       prompts again.
  625.    
  626.       ?I/O ERROR
  627.    
  628.          Indicates that a error has occured in the tape system,  Check  for
  629.       bad tape.
  630.    MICRO BASIC USERS GUIDE                                          Page: 14
  631.  
  632.  
  633.    7. SOURCE FORMAT
  634.    
  635.          Micro Basic programs are stored  in  memory,  as  variable  length
  636.       records, separated by carriage return character (0D hex). The end  of
  637.       the program is marked by a  line  starting  with  a  hexidecimal  FF.
  638.       Program lines are in the following format:
  639.    
  640.          -------------------------------------------------
  641.          |2 bytes|1 byte| variable length section |1 byte|
  642.          -------------------------------------------------
  643.            \___/   \__/   \_____________________/  \____/
  644.              ^       ^              ^                 ^_ Carriage Return.
  645.              ^       ^              ^
  646.              ^       ^              ^___________________ Program text.
  647.              ^       ^
  648.              ^       ^__________________________________ Length of remainder
  649.              ^                                           of line. (+11 hex)
  650.              ^
  651.              ^__________________________________________ Packed decimal line
  652.                                                          number (0000-9999).
  653.                                                          (FFxx=end of prog.)
  654.    MICRO BASIC USERS GUIDE                                          Page: 15
  655.  
  656.  
  657.    8. EXAMPLE PROGRAMS
  658.    
  659.          The  following  are  some  simple  Micro  Basic  programs,   which
  660.       demonstrate many of the features of the language. A good excercise to
  661.       gain experience with the interpreter, is to enter and run  them,  and
  662.       observe the results.
  663.    
  664.      0010 REM THIS PROGRAM PLAYS THE HIGH/LOW GAME.
  665.      0020 PRINT "I WILL PICK A NUMBER BETWEEN 1 AND 100"
  666.      0030 PRINT "THEN I WANT YOU TO TRY AND GUESS IT."
  667.      0040 PRINT "I WILL TELL YOU IF YOU ARE TOO HIGH, OR TOO LOW"
  668.      0050 C=0
  669.      0060 N=1+R;?%100
  670.      0070 INPUT "WHAT IS YOUR GUESS?",G
  671.      0080 C=C+1
  672.      0090 LIF G==N THEN PRINT "YOU GUESSED IT IN ",C," GUESSES!":END
  673.      0100 IF G>N THEN PRINT "YOU ARE TOO HIGH."
  674.      0110 IF G<N THEN PRINT "YOU ARE TOO LOW."
  675.      0120 GOTO 70
  676.    
  677.      0010 REM THIS PROGRAM WILL COUNT FROM 1 TO 10, AND DISPLAY
  678.      0020 REM THE COUNT, BOTH AS A NUMBER, AND AS A WORD.
  679.      0030 ORDER 60 : FOR I=1 TO 10
  680.      0040 READ I$ : PRINT I," ",I$
  681.      0050 NEXT I
  682.      0060 DATA "ONE","TWO","THREE","FOUR","FIVE"
  683.      0070 DATA "SIX","SEVEN","EIGHT","NINE","TEN"
  684.    
  685.      0010 REM THIS PROGRAM WILL INPUT N NUMBERS, AND PRINT THEM
  686.      0020 REM OUT IN REVERSE ORDER.
  687.      0030 INPUT"HOW MANY NUMBERS?",N:DIM A(N):FORI=1TON
  688.      0040 PRINT"NUMBER ",I,:INPUT X:A[I]=X:NEXT I
  689.      0050 PRINT"NOW HERE THEY ARE BACKWARDS."
  690.      0060 FOR I=0 TO N-1:PRINT" ",A[N-I],:NEXTI:PRINT""
  691.    
  692.      0010 REM THIS PROGRAM WILL DISPLAY THE ASCII CHARACTER SET.
  693.      0020 FOR I=0 TO 127:PRINT @[I]$:NEXTI:PRINT""
  694.    
  695.      0010 REM THIS PROGRAM WILL DISPLAY THE CONTENTS OF MEMORY
  696.      0020 REM FROM 0000 TO 07FF IN DECIMAL.
  697.      0030 FOR I=0 TO 7FF# : PRINT @[I],:NEXT I : PRINT "" 
  698.    
  699.      0010 REM THIS PROGRAM WILL DISPLAY THE CONTENTS OF MEMORY
  700.      0020 REM FROM 0000 TO 07FF IN ASCII.
  701.      0030 FOR I=0 TO 7FF# : PRINT @[@[I]]$," ", : NEXT I : PRINT ""
  702.    
  703.      0010 REM THIS PROGRAM WILL INPUT A NUMBER, AND PRINT IT IN HEX.
  704.      0020 REM NOTE THE USE OF MOD. ARITHMETIC, AND CHAR. VARIABLE INDEX.
  705.      0030 R$="":H$="0123456789ABCDEF":INPUTN
  706.      0040 R$=H[R;N=N%16]$+R$:IFN>0THEN40
  707.      0050 PRINT R$
  708.    MICRO BASIC USERS GUIDE                                          Page: 16
  709.  
  710.  
  711.    9. THE MICRO BASIC MONITOR
  712.    
  713.          The MICRO BASIC roms include a  machine  language  MONITOR,  which
  714.       allows you to read/write memory, load and dump memory to tape, etc.
  715.    
  716.          The monitor has its own set of commands,  which  can  be  entered,
  717.       whenever the system is RESET, or  when  ever  BASIC  is  exited  (via
  718.       EXIT). Operands to commands are read (and executed) as  soon  as  you
  719.       type them in (no carriage return is needed). Hexidecimal  BYTE  (<b>)
  720.       values must be entered as TWO characters  (eg  5F),  and  WORD  (<w>)
  721.       values must be entered using four characters (eg 00A5).
  722.    
  723.          A summary of commands followes:
  724.    
  725.      B                 Enters the BASIC interpreter,  initializing program,
  726.                        variables, and arrays.
  727.    
  728.      D                 Downloads Intel hex format through the terminal port.
  729.    
  730.      G <w1>            Go, Begins execution at address <w1>
  731.    
  732.      L                 Loads from tape, indicates record count when  done
  733.                        (in hex).
  734.    
  735.      M <w1>,<w2>       Displays MEMORY from <w1>, to <w2>.
  736.    
  737.      R                 Reenters BASIC, preserving existing program. Should
  738.                        not be used when the system is first turned on.
  739.    
  740.      S <w1> XX-<b2>    Substitutes into memory, starting at address <w1> ,
  741.                        Displays contents as XX, entering <b2> will replace
  742.                        XX and advance to the next. Entering a  space  will
  743.                        skip to the next, without changeing, and a carriage-
  744.                        return will exit to monitor.
  745.    
  746.      T <H> or <F>      Enters terminal mode. Simulates an  ASCII  terminal
  747.                        Operating in either <Full> or <Half> duplex. Serial
  748.                        port is tape port.
  749.    
  750.      U <w>             Initalizes the 8251 usart with the value <w>.  See
  751.                        INTEL 8251 documentation.
  752.      W <w1>,<w2>       Writes memory from <w1> to <w2> to tape.
  753.    MICRO BASIC USERS GUIDE                                          Page: 17
  754.  
  755.  
  756.    9.1 MONITOR SUBROUTINES
  757.    
  758.      Address  |Regs.|             Description of
  759.    (Hex)|(Dec)|Used |             Subroutine
  760.    -----+-----------+-------------------------------------------------------
  761.    0037 |0055 |All  | Entry point to monitor.
  762.    -------------------------------------------------------------------------
  763.    00D6 |0214 |     | Writes memory to tape, DE=start addr., HL=end addr.
  764.    -------------------------------------------------------------------------
  765.    0162 |0354 |None | Outputs character in A to output device.
  766.    -------------------------------------------------------------------------
  767.    027E |0638 |None | Checks terminal for CONTROL-C, sets Z if so, LF halts.
  768.    -------------------------------------------------------------------------
  769.    023F |0575 |  A  | Gets a character for A from input device.
  770.    -------------------------------------------------------------------------
  771.    02EB |0747 |     | Gets a record from tape, Carry=1 if more data, 0=EOF.
  772.    -------------------------------------------------------------------------
  773.    034E |0846 |     | Displays message (HL) up to ZERO or carriage return.If
  774.         |     |     | carriage return is found, then LF, CR pair is printed.
  775.    -------------------------------------------------------------------------
  776.    035B |0859 |     | Displays a line-feed, carriage return on the screen.
  777.    -------------------------------------------------------------------------
  778.    037E |0894 |     | Positions cursor at position in HL in video display.
  779.    -------------------------------------------------------------------------
  780.    0396 |0918 |     | Starts Cassette deck, and provides delay for speed.
  781.    -------------------------------------------------------------------------
  782.    03A6 |0934 |     | Stops Cassette deck.
  783.    -------------------------------------------------------------------------
  784.         |     |     | Displays byte in A on output devices in HEX.
  785.    -------------------------------------------------------------------------
  786.         |     |     | Displays word in HL on output devices in HEX.
  787.    -------------------------------------------------------------------------
  788.         |     |     | Gets HEX byte for A from input, CY=0 if failure.
  789.    -------------------------------------------------------------------------
  790.         |     |     | Gets HEX word for HL from input, CY=0 if failure.
  791.    -------------------------------------------------------------------------
  792.    0400 |1024 | All | Cold start entry point for  BASIC,  the  program  and
  793.         |     |     | variables will be lost, and basic will be started.
  794.    -------------------------------------------------------------------------
  795.    040D |1037 | All | Warm start entry point for  basic,  the  program  and
  796.         |     |     | variables will remain intact.
  797.    -------------------------------------------------------------------------
  798.    048F |1167 |None | Tests character in A and sets carry flag if it is NOT
  799.         |     |     | a valid ASCII numeric digit. ('0' - '9').
  800.    -------------------------------------------------------------------------
  801.    0499 |1177 | All | Gets a line from  the  terminal.  All  BASIC  editing
  802.         |     |     | commands can be used. If CONTROL-C is entered, causes
  803.         |     |     | a warm start to BASIC. On exit, D-E is left  pointing
  804.         |     |     | to line just entered.
  805.    -------------------------------------------------------------------------
  806.    MICRO BASIC USERS GUIDE                                          Page: 18
  807.  
  808.  
  809.    -------------------------------------------------------------------------
  810.    067C |1660 | All | Looks up command word (Ending with <space>  or  <cr>)
  811.         |     |     | pointed to by D-E, in table pointed to by H-L.  Table
  812.         |     |     | format is words in memory, followed by a  blank,  and
  813.         |     |     | an address to be returned. End table  with  a  single
  814.         |     |     | blank, and default address. On exit, A contains value
  815.         |     |     | indicating which word in table was found. (0,1,2,...)
  816.         |     |     | and H-L contains associated address.
  817.    -------------------------------------------------------------------------
  818.    06A8 |1704 |A,B,C| Clears all BASIC variables and arrays, and resets the
  819.         |     | H,L | FOR/NEXT, GOSUB/RETURN control stack pointer.
  820.    -------------------------------------------------------------------------
  821.    06C6 |1734 |A,H,L| As above, but integer and character variables remain.
  822.    -------------------------------------------------------------------------
  823.    06CC |1740 |A,H,L| As above, but only arrays are cleared, stack remains.
  824.    -------------------------------------------------------------------------
  825.    077E |1918 |None | Pushes single byte in A on BASIC control stack.
  826.    -------------------------------------------------------------------------
  827.    0789 |1929 |  A  | Pops single byte to A from BASIC control stack.
  828.    -------------------------------------------------------------------------
  829.    0792 |1938 |None | Pushes word in D-E on BASIC control stack.
  830.    -------------------------------------------------------------------------
  831.    079C |1948 | D,E | Pops word to D-E from BASIC control stack.
  832.    -------------------------------------------------------------------------
  833.    07C9 |1993 |None | Sets carry flag if character in A is not 'A'-'Z'.
  834.    -------------------------------------------------------------------------
  835.    07D0 |2000 |ABCHL| Stores value in HL into integer variable passed in A.
  836.    -------------------------------------------------------------------------
  837.    07E1 |2017 |ABCHL| Reads value for HL from integer variable passed in A.
  838.    -------------------------------------------------------------------------
  839.    07EE |2030 |A,D,E| Advances to next  non-blank  character  in  the  line
  840.         |     |     | Pointed to by the D-E register pair.
  841.    -------------------------------------------------------------------------
  842.    0822 |2082 | All | Evaluates BASIC expression pointed to by D-E,  ending
  843.         |     |     | with a carriage return or ':'.  Integer  results  are
  844.         |     |     | returned in H-L.
  845.    -------------------------------------------------------------------------
  846.    08E8 |2280 |ABCHL| Multiply HL by BC, result in HL.
  847.    -------------------------------------------------------------------------
  848.    091D |2333 | All | Divide HL by BC, result in DE, remainder in HL.
  849.    -------------------------------------------------------------------------
  850.    0B88 |2952 | All | Displays number in H-L in decimal.
  851.    -------------------------------------------------------------------------
  852.    0C86 |3206 |ABCHL| Returns in HL the address of the  character  variable
  853.         |     |     | passed in A. Character variable format is  35  chars,
  854.         |     |     | unused characters at end are padded with $FF.
  855.    -------------------------------------------------------------------------
  856.    MICRO BASIC USERS GUIDE                                          Page: 19
  857.  
  858.  
  859.             The MONITOR keeps a byte of data which defines how I/O will  be
  860.          handled. It is  located  at  address  $14FF  (5375),  and  can  be
  861.          modified by the basic interpreter (or machine  language  program).
  862.          It is as followes:
  863.    
  864.          Bits in I/O configuration byte.
  865.          +---+---+---+---+---+---+---+---+
  866.          | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |    (Initial value is 00000011)
  867.          +---+---+---+---+---+---+---+---+
  868.            |   |   |   |   |   |   |   |
  869.            |   |   |   |   |   |   |   +--- 0 = Read from Uart.
  870.            |   |   |   |   |   |   |        1 = Read from Keyboard.
  871.            |   |   |   |   |   |   +------- 1 = Output to Video Display.
  872.            |   |   |   |   |   +----------- 1 = Output to Uart. (8251)
  873.            |   |   |   |   +--------------- 1 = Output to User Supplied
  874.            |   |   |   |                        Output Device (See Below).
  875.            |   |   |   +------------------- 0 = Translate input to upper case.
  876.            |   |   |                        1 = Disable UPPER CASE translation.
  877.            |   |   +----------------------- 1 = Disable CONTROL-C interrupts.
  878.            |   +--------------------------- 1 = Inhibit all output.
  879.            +------------------------------- 1 = Set Bit 7 in all characters
  880.                                                 output to Video Display.
  881.    
  882.             For example, to prevent a CONTROL-C stop from the keyboard, you
  883.          could use the following statement:
  884.    
  885.                            ' @[5375]=@[5375]|20# '
  886.    
  887.             To reenable CNTRL-C stops, you would use:
  888.    
  889.                            ' @[5375]=@[5375]&DF# '.
  890.    
  891.       9.2 USER SUPPLIED OUTPUT DEVICE
  892.    
  893.             The system normally supports  two  output  devices,  the  VIDEO
  894.          DISPLAY, and the 8251 UART. In addition, it supports  one  logical
  895.          output device, to be defined by the user. This is useful for doing
  896.          translations before you output a character as well.  To  use  this
  897.          feature, you must supply a machine language output routine in  ram
  898.          (somewhere outside  the  range  used  by  the  interpreter,  basic
  899.          program, and any arrays). Then, store the address of  the  routine
  900.          in the USER DEVICE VECTOR, which is located at addresses 14FD  and
  901.          14FE (5373-5374), the low order address byte must  go  first.  The
  902.          logical user output device is now defined, and can be  enabled  by
  903.          setting bit 3 of the  I/O  config.  byte.  NOTE1:  Output  may  be
  904.          directed to more than one device at once. NOTE2: If bit#3  of  the
  905.          I/O config. byte is set to  1,  before  you  initialize  the  USER
  906.          DEVICE VECTOR, Your computer will probably  crash  (And  you  will
  907.          lose any unsaved programs).
  908.    
  909.             When the user routine is called, the character to be printed is
  910.          passed in the B-REG, and I/O config. byte is passed in recister C.
  911.          All of the processor registers may be modified by the subroutine.
  912.    MICRO BASIC USERS GUIDE                                          Page: 20
  913.  
  914.  
  915.       9.3 8251 USART
  916.    
  917.             The 8251 usart, is initialized to 1 stop bit, 7 data  bits,  no
  918.          parity, and baud rate of 1/16 times  the  rx  and  tx  clocks.  To
  919.          indicate when a tape operation is currently under way, the DSR pin
  920.          of the 8251 will be set HIGH (+5v), and  LOW  (0v)  at  all  other
  921.          times. A short delay is produced from the time this pin goes high,
  922.          and a write to tape operation occures. This allows it to  be  used
  923.          as a start/stop control for the tape machine, allowing the tape to
  924.          get up to speed.
  925.    
  926.    10. SYSTEM MEMORY MAP
  927.    
  928.          The memory is used by the interpreter as follows:
  929.    
  930.         ADDRESS-RANGE             DESCRIPTION OF CONTENTS.
  931.    
  932.           0000-0FFF   (4k)        Micro Basic Roms.
  933.           1000-13FF   (1k)        Memory Mapped Video Display.
  934.           1400-14FC   (253 Bytes) Input buffer, Machine stack, Internal storege.
  935.           14FD-14FE   (2 Bytes)   User Device Vector.
  936.           14FF        (1 Byte)    I/O Configuration byte.
  937.           1500-15FF   (256 Bytes) Edit Buffer, Control stack, Internal storage.
  938.           1600-19FF   (1k)        Fixed integer and character variables, flags.
  939.           1A00-FFFF   (Any size)  Program and Array storage.
  940.    
  941.          When not using the Basic Interpreter (Executing  machine  language
  942.       programs from the monitor), Any memory starting at 1500 or higher can
  943.       be used without affecting the system. NOTE: Any time  you  enter  the
  944.       basic interpreter, anything stored from 1500 to  1CFF  may  be  lost,
  945.       Even if you do not enter any program text when in Basic.
  946.  
  947.  
  948.  
  949.                            MICRO BASIC USERS GUIDE
  950.  
  951.                               TABLE OF CONTENTS
  952.  
  953.  
  954.                                                                         Page
  955.  
  956.     1. INTRODUCTION                                                        1
  957.  
  958.  
  959.     2. COMMANDS                                                            2
  960.  
  961.        2.1 General commands                                                2
  962.        2.2 Program only commands                                           5
  963.  
  964.     3. EXPRESSIONS                                                         6
  965.  
  966.        3.1 Numeric operators                                               6
  967.        3.2 Character operators                                             7
  968.        3.3 Numeric conversion                                              7
  969.        3.4 Variables                                                       8
  970.        3.5 Special variables                                               9
  971.  
  972.     4. PROGRAM ENTRY AND EDITING                                          10
  973.  
  974.  
  975.     5. CONTROL CHARACTERS                                                 12
  976.  
  977.  
  978.     6. ERROR MESSAGES                                                     13
  979.  
  980.  
  981.     7. SOURCE FORMAT                                                      14
  982.  
  983.  
  984.     8. EXAMPLE PROGRAMS                                                   15
  985.  
  986.  
  987.     9. THE MICRO BASIC MONITOR                                            16
  988.  
  989.        9.1 MONITOR SUBROUTINES                                            17
  990.        9.2 USER SUPPLIED OUTPUT DEVICE                                    19
  991.        9.3 8251 USART                                                     20
  992.  
  993.     10. SYSTEM MEMORY MAP                                                 20
  994.  
  995.